from UserInterface.InstructionSrc import InstructionSrc 
from UserInterface.UIException import *
import re

class TextInstructionSrc(InstructionSrc):
    def __init__(self, file:str) -> None:
        super().__init__()
        with open(file, 'r') as f:
            self.instLines = f.readlines()
        self.lineId = 0

    def GetInstruction(self) -> tuple:
        if self.lineId >= len(self.instLines):
            raise UIEndofInput()
        instStr = self.instLines[self.lineId]
        self.lineId += 1
        instStr = instStr.strip()
        if not instStr:
            raise UIBlankInput()
        return tuple(re.split(r'\s+', instStr))
